package com.woniuxy.reader.mapper;

import com.woniuxy.reader.entity.Editor;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.woniuxy.reader.vo.AuthorVOO;
import com.woniuxy.reader.vo.EditorVO;
import com.woniuxy.reader.vo.EditorVOO;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author zh_o
 * @since 2020-10-12
 */
public interface EditorMapper extends BaseMapper<Editor> {
    /**
     * 查询自己签约的作者以及状态
     */
    @Select("select a.pen_name,a.name,a.author_tel,a.author_id,a.sex from author a LEFT JOIN editor e ON a.editor_id=e.editor_id where e.editor_tel=#{authortel} and a.`level`='签约写手'")
    List<AuthorVOO> selectSignUp(String editortel);

    /**
     * 查询所有编辑：查询所有的编辑数据，包括签约的作者，作品数等
     * @return
     */
    @Select("select e.editor_id,e.editor_tel,e.status,a.author_id,a.pen_name from editor e LEFT JOIN author a on e.editor_id=a.editor_id")
    List<EditorVOO> selectAllSignEditor();

    @Update("update author set level='未签约' where author_id=#{authorid}")
    void updateByAuthorId(int authorid);
}
